#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <mysql/mysql.h>
#include <vector>
#include"server.hpp"



#define HOST "127.0.0.1"
#define PORT 3306
#define USER "root"
#define PASS "@jiangzhe2021"
#define GOMOKU "gomoku"
void test_mysql()
{
    MYSQL *mysql = mysql_util::mysql_create(HOST, USER, PASS, GOMOKU, PORT);
    const char *sql = "insert student values(null, '小江', 18, 53, 68, 87);";
    bool ret = mysql_util::mysql_exec(mysql, sql);
    if (ret == false)
    {
        return;
    }
    mysql_util::mysql_destory(mysql);
}
void test_json()
{
    Json::Value root;
    std::string body;
    root["姓名"] = "张三";
    root["年龄"] = 20;
    root["成绩"].append(99);
    root["成绩"].append(88);
    root["成绩"].append(77);
    json_util::serialize(root, body);

    LOG(DEBUG, "%s\n", body.c_str());

    Json::Value val;
    json_util::unserialize(body, val);
    std::cout << "姓名:" << val["姓名"].asString() << std::endl;
    std::cout << "年龄:" << val["年龄"].asInt() << std::endl;
    int sz = val["成绩"].size();
    for (int i = 0; i < sz; i++)
    {
        std::cout << "成绩：" << val["成绩"][i].asFloat() << std::endl;
    }
    return;
}
void test_split()
{
    std::string str = ",,,,,....,,,,123,,,,456,,,789,,,";
    std::cout << str << std::endl;
    std::vector<std::string> array;
    string_util::split(str, ",", array);
    for (auto s : array)
    {
        std::cout << s << std::endl;
    }
}
void test_read()
{
    const std::string filename = "./Makefile";
    std::string body;
    file_util::read(filename, body);
    std::cout << body << std::endl;
}
void test_dp()
{
    user_table ut(HOST, USER, PASS, GOMOKU, PORT);
    Json::Value user;
    user["username"] = "xiaoming";
    // user["password"] = "12345";
    bool ret = ut.insert(user);
    // bool ret = ut.login(user);
    // if(ret == false)
    // {
    //     LOG(DEBUG,"login failed!\n");
    // }
    // bool ret = ut.select_by_id(1,user);
    // std::string body;
    // json_util::serialize(user,body);
    // std::cout<<body<<std::endl;
    // bool ret = ut.win(1);
    // bool ret = ut.lose(1);
}
void test_online()
{
    online_manager om;
    uint64_t uid = 2;
    websocketsvr::connection_ptr con;
    om.enter_game_room(uid, con);
    if (om.is_in_game_room(uid))
    {
        std::cout << "在游戏大厅中" << std::endl;
    }
    else
    {
        std::cout << " 不在游戏大厅" << std::endl;
    }
    om.exit_game_room(uid);
    if (om.is_in_game_room(uid))
    {
        std::cout << "在游戏大厅中" << std::endl;
    }
    else
    {
        std::cout << " 不在游戏大厅" << std::endl;
    }
}
int main()
{
    EnableScrean();
    // test_json();
    // test_split();
    // test_read();
    // test_dp();
    // test_online();
    // user_table ut(HOST, USER, PASS, GOMOKU, PORT);
    // onlien_manager om;
    // // room r(10,&ut,&om);
    // room_manage rm(&ut,&om);
    // room_ptr rp = rm.cteate_room(10,20);
    // match_manage mc(&rm,&ut,&om);

    gomoku_server server(HOST, USER, PASS, GOMOKU, PORT);
    server.start(8085);
    return 0;
}